package ioc

import (
	ratelimit2 "gitee.com/xiao_hange/go-admin-pkg/pkg/ratelimit"
	"github.com/redis/go-redis/v9"
	"github.com/spf13/viper"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	tsms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111"
	"go-admin/server/internal/service/sms"
	"go-admin/server/internal/service/sms/ratelimit"
	"go-admin/server/internal/service/sms/tencent"
	"time"
)

func InitTencentSms(client redis.Cmdable) sms.Service {
	config := viper.GetStringMapString("sms.tencent")
	c, err := tsms.NewClient(common.NewCredential(config["secretid"], config["secretkey"]),
		config["region"],
		profile.NewClientProfile())
	if err != nil {
		panic(err)
	}
	smsSvc := tencent.NewService(c, config["appid"], config["signaname"])
	return ratelimit.NewRateLimitSMSService(smsSvc, ratelimit2.NewRedisSlideWindowLimiter(client, time.Second, 100))
}

//etcd 实时获取
//func InitTencentSms(client redis.Cmdable, conf *conf.SettingConfig) sms.Service {
//	var smsSvc sms.Service
//	if conf == nil {
//		return smsSvc
//	}
//	c, err := tsms.NewClient(common.NewCredential(conf.SMS.Tencent.SecretId, conf.SMS.Tencent.SecretKey),
//		conf.SMS.Tencent.Region,
//		profile.NewClientProfile())
//	if err != nil {
//		panic(err)
//	}
//	smsSvc = tencent.NewService(c, conf.SMS.Tencent.AppId, conf.SMS.Tencent.SignaName)
//	smsSrv := ratelimit.NewRateLimitSMSService(smsSvc, ratelimit2.NewRedisSlideWindowLimiter(client, time.Second, 100))
//	//global.SMS = smsSrv       实时获取远程配置中心数据
//	return smsSrv
//}

//func InitAliSms(client redis.Cmdable) sms.Service {
//	config := viper.GetStringMapString("sms.tencent")
//	c, err := dysmsapi.NewClientWithAccessKey(config["region"], config["secretid"], config["secretkey"])
//	if err != nil {
//		return nil
//	}
//	smsSvc := aliyun.NewService(c, config["signaname"])
//	return ratelimit.NewRateLimitSMSService(smsSvc, ratelimit2.NewRedisSlideWindowLimiter(client, time.Second, 100))
//}
